package top.kangyaocoding.ltzf.payment.nativepay.model;

import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import lombok.Getter;
import top.kangyaocoding.ltzf.utils.SignUtils;

import java.util.HashMap;

/**
 * @Author K·Herbert
 * @Description
 * @Date 2024-05-14 16:00
 */

@Data
public class PrepayRequest {
    @JsonProperty("mch_id")
    private String mchId;

    @JsonProperty("out_trade_no")
    private String outTradeNo;

    @JsonProperty("total_fee")
    private String totalFee;

    @JsonProperty("body")
    private String body;

    @JsonProperty("notify_url")
    private String notifyUrl;

    @JsonProperty("attach")
    private String attach;

    @JsonProperty("time_expire")
    private String timeExpire;

    @JsonProperty("developer_appid")
    private String developerAppId;

    @JsonProperty("sign")
    private String sign;

    @Getter
    private String timestamp = String.valueOf(System.currentTimeMillis() / 1000);

    public String createSign(String key) {
        HashMap<String, String> dataMap = new HashMap<>();
        dataMap.put("mch_id", getMchId());
        dataMap.put("out_trade_no", getOutTradeNo());
        dataMap.put("total_fee", getTotalFee());
        dataMap.put("body", getBody());
        dataMap.put("timestamp", getTimestamp());
        dataMap.put("notify_url", getNotifyUrl());

        return SignUtils.createSign(dataMap, key);
    }
}
